package com.fate.system.controller;

import com.fate.system.service.IApprovalService;
import com.fate.system.dto.approval.ApprovalAddDTO;
import com.fate.system.vo.approval.ApprovalListVO;
import com.fate.system.vo.approval.ApprovalDetailVO;
import com.fate.system.dto.approval.ApprovalUpdateDTO;
import com.fate.system.entity.Approval;

import com.fate.framework.dto.IdParamDTO;
import com.fate.framework.utils.SystemUtil;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import com.fate.system.dto.approval.ApprovalPageDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

@Tag(name = " API")
@RestController
@RequestMapping("/api/v1.0/approval")
public class ApprovalController {

  @Resource private IApprovalService approvalService;

  @Operation(summary = "新增")
  @PostMapping("/add")
  public void add(@RequestBody @Valid ApprovalAddDTO addDTO) {
    Approval approval = SystemUtil.buildResource(addDTO, Approval.class);
    approvalService.save(approval);
  }

  @Operation(summary = "删除")
  @PostMapping("/remove")
  public void remove(@RequestBody @Valid IdParamDTO idParamDTO) {
    approvalService.removeById(idParamDTO.getId());
  }

  @Operation(summary = "更新")
  @PostMapping("/update")
  public void update(@RequestBody @Valid ApprovalUpdateDTO updateDTO) {
    Approval approval = SystemUtil.buildResource(updateDTO, Approval.class);
    approvalService.updateById(approval);
  }

  @Operation(summary = "详情")
  @PostMapping("/detail")
  public ApprovalDetailVO detail(@RequestBody @Valid IdParamDTO idParamDTO) {
    Approval approval = approvalService.getById(idParamDTO.getId());
    return SystemUtil.buildResource(approval, ApprovalDetailVO.class);
  }

  @Operation(summary = "分页列表")
  @PostMapping("/getPageList")
  public Page<ApprovalListVO> getPageList(@RequestBody @Valid ApprovalPageDTO pageDTO) {
    Page<Approval> page = approvalService.getPageList(pageDTO);
    return SystemUtil.buildResource(page, ApprovalListVO.class);
  }
}
